//package ui.forms;
//
//import base.Food;
//import base.Intake;
//import db.IntakeManager;
//import utils.DateUtils;
//import com.sun.lwuit.*;
//import com.sun.lwuit.events.*;
//import com.sun.lwuit.layouts.*;
//import com.sun.lwuit.plaf.Border;
//import db.FoodManager;
//import java.util.Vector;
//import ui.IntakeItem;
//import ui.IntakeListRenderer;
//
///**
// * Displays the intakes for a particular date
// * @author MEERA, Shayan
// */
//public class DetailedReportForm extends Form implements ActionListener {
//
//    private Label month;
//    private Label year;
//    private Label day;
//    private String strDate = new String();
//    public Object[] intakeItem = new Object[25];
//    private final Command cmdDec;
//    private final Command cmdInc;
//    private final List lstIn;
//    private final IntakeListRenderer inlstRenderer;
//    private final int formWidth;
//    private final int formHeight;
//    private static final Command backCommand = new Command("Back", 0);
//    Form parent;
//
//    DetailedReportForm(Form parent, String strDate) {
//        this.setTitle("Report Form");
//        this.parent = parent;
//        this.setDate(strDate);
//        this.setLayout(new BorderLayout());
//        formWidth = this.getPreferredW();
//        formHeight = this.getPreferredH();
//        Label title1 = new Label("Item");
//        Label title2 = new Label("Qty");
//        Label title3 = new Label("Unit");
//        Label title4 = new Label("KCal");
//        title1.getStyle().setBorder(Border.createLineBorder(1, 0x000000));
//        title2.getStyle().setBorder(Border.createLineBorder(1, 0x000000));
//        title3.getStyle().setBorder(Border.createLineBorder(1, 0x000000));
//        title4.getStyle().setBorder(Border.createLineBorder(1, 0x000000));
//        title1.setPreferredW(80);
//        title2.setPreferredW(40);
//        title3.setPreferredW(40);
//        title4.setPreferredW(60);
//
//        cmdDec = new Command("<");
//        cmdInc = new Command(">");
//
//        lstIn = new List();
//        inlstRenderer = new IntakeListRenderer();
//        this.setList(this.strDate);
//        lstIn.setSmoothScrolling(true);
//        lstIn.getStyle().setBorder(Border.createLineBorder(1, 0x000000));
//        lstIn.setListCellRenderer(inlstRenderer);
//        lstIn.setPreferredW(formWidth);
//        lstIn.setPreferredH(formHeight * 2 / 3);
//        final Button btnDec = new Button(cmdDec);
//        final Button btnInc = new Button(cmdInc);
//
//        day = new Label(strDate.substring(0, 2));
//        month = new Label(strDate.substring(3, 5));
//        year = new Label(strDate.substring(6, 10));
//
//        final Container upper = new Container(new FlowLayout(Component.CENTER));
//        final Container cnt = new Container(new BoxLayout(BoxLayout.X_AXIS));
//        cnt.addComponent(btnDec);
//        final Container dateCnt = new Container(new BoxLayout(BoxLayout.X_AXIS));
//        dateCnt.addComponent(day);
//        dateCnt.addComponent(month);
//        dateCnt.addComponent(year);
//        cnt.addComponent(dateCnt);
//        cnt.addComponent(btnInc);
//        upper.addComponent(cnt);
//
//        final Container centreCon = new Container(new BoxLayout(BoxLayout.Y_AXIS));
//        Container cnt1 = new Container(new BoxLayout(BoxLayout.X_AXIS));
//        cnt1.addComponent(title1);
//        cnt1.addComponent(title2);
//        cnt1.addComponent(title3);
//        cnt1.addComponent(title4);
//        centreCon.addComponent(cnt1);
//        centreCon.addComponent(lstIn);
//
//        this.addComponent(BorderLayout.NORTH, upper);
//        this.addComponent(BorderLayout.CENTER, centreCon);
//
//        this.addCommand(backCommand);
//        this.setBackCommand(backCommand);
//
//        this.addCommandListener(this);
//        btnInc.addActionListener(new ActionListener() {
//
//            public void actionPerformed(ActionEvent evt) {
//                if (evt.getCommand() == cmdInc) {
//
//                    String nextDay = DateUtils.DatetoString(
//                            DateUtils.getNextDay(
//                            DateUtils.stringToDate(day.getText() +
//                            "/" +
//                            month.getText() +
//                            "/" +
//                            year.getText())));
//                    day.setText(nextDay.substring(0, 2));
//                    month.setText(nextDay.substring(3, 5));
//                    year.setText(nextDay.substring(6, 10));
//                    day.repaint();
//                    month.repaint();
//                    year.repaint();
//                    setList(day.getText() + "/" + month.getText() + "/" + year.getText());
//                    lstIn.repaint();
//                    btnInc.setFocus(true);
//
//                }
//            }
//        });
//        btnDec.addActionListener(new ActionListener() {
//
//            public void actionPerformed(ActionEvent evt) {
//                if (evt.getCommand() == cmdDec) {
//
//
//                    String prevDay = DateUtils.DatetoString(
//                            DateUtils.getYesterday(
//                            DateUtils.stringToDate(day.getText() +
//                            "/" +
//                            month.getText() +
//                            "/" +
//                            year.getText())));
//                    day.setText(prevDay.substring(0, 2));
//                    month.setText(prevDay.substring(3, 5));
//                    year.setText(prevDay.substring(6, 10));
//                    day.repaint();
//                    month.repaint();
//                    year.repaint();
//                    setList(day.getText() + "/" + month.getText() + "/" + year.getText());
//                    lstIn.repaint();
//                    btnDec.setFocus(true);
//                }
//            }
//        });
//    }
//
//    public void setDate(String date) {
//        this.strDate = date;
//    }
//
//    public void setList(String strDate) {
//        try {
//            for (int i = lstIn.size(); i >= 0; i--) {
//                lstIn.getModel().removeItem(i);
//            }
//            lstIn.repaint();
//            Vector result = IntakeManager.getDailyIntakes(
//                    Context.currentUser.getId(),
//                    DateUtils.stringToDate(strDate));
//
//            for (int i = 0; i < result.size(); i++) {
//                Intake intake = (Intake) result.elementAt(i);
//                Food food = FoodManager.getById(intake.getFoodId());
//                intakeItem[i] = new IntakeItem(
//                        food.getName(),
//                        Float.toString(intake.getQuantity()),
//                        intake.getUnit(),
//                        Float.toString(intake.getCalories()));
//                lstIn.addItem(intakeItem[i]);
//            }
//            lstIn.repaint();
//        } catch (Exception ex) {
//            ex.printStackTrace();
//            Dialog.show("Error", ex.toString(), "OK", "");
//        }
//    }
//
//    public void actionPerformed(ActionEvent evt) {
//        if (evt.getCommand() == backCommand) {
//            parent.showBack();
//        }
//    }
//}
